<?
function el_extract($str, $prefix, $suffix = '', $inclusive = false) {
  if ($prefix != '') {
    $pos = strpos($str, $prefix);
    if (!($pos === false)) {
      $str = substr($str, $pos + ($inclusive?0:strlen($prefix)));
    }
    else {
      return '';
    }
  }
  if ($suffix != '') {
    $pos = strpos($str, $suffix);
    if (!($pos === false)) {
      $str = substr($str, 0, $pos + ($inclusive?strlen($suffix):0));
    }
    else {
      return '';
    }
  }

  return $str;
}

function el_iextract($str, $prefix, $suffix = '', $inclusive = false) {
  if ($prefix != '') {
    $pos = stripos($str, $prefix);
    if (!($pos === false)) {
      $str = substr($str, $pos + ($inclusive?0:strlen($prefix)));
    }
    else {
      return '';
    }
  }
  if ($suffix != '') {
    $pos = stripos($str, $suffix);
    if (!($pos === false)) {
      $str = substr($str, 0, $pos + ($inclusive?strlen($suffix):0));
    }
    else {
      return '';
    }
  }

  return $str;
}

function set_curl_useragent($curl) {
  curl_setopt($curl, CURLOPT_USERAGENT, 'iSiloX/4.xx Windows/32');
}

function normalize_url($url) {
  global $token;

  if (strncmp($url, 'http://', 7) && strncmp($url, 'https://', 8)) {
    if (strncmp($url, '/', 1)) {
      $url = 'http://pda.atnext.com/isilo/'.$url;
    }
    else {
      $url = 'http://pda.atnext.com'.$url;
    }
  }

  if (strstr($url, '&aToken=') === false && strstr($url, '?aToken=') === false) {
    $url = $url.(strstr($url, '?') === false?'?':'&').'aToken='.$token;
  }

  return $url;
}
?>